import { Utils } from "../Utils/Utils"

/**
 * csv class 基类 可以实现一些通用方法
 */
export class BaseCsv {
    public readonly typeStr: any
    private static csvData: Map<string, Map<number, any>> = new Map<string, Map<number, any>>()


    public static loadData<T extends BaseCsv, T1>(name: string, asset: T1, t: { new(): T }) {
        BaseCsv.csvData.set(name, Utils.convert<T, T1>(asset, t))
    }

    /**
     * 获取表单条数据
     * @param name 
     * @param id 
     * @returns 
     */
    public static getData<T extends BaseCsv>(name: string, id: number): T {
        if (BaseCsv.csvData.has(name)) {
            let data = BaseCsv.csvData.get(name)
            if (data.has(id)) {
                return data.get(id)
            }
        }
        return null
    }
    /**
     * 获取表所有数据
     * @param name 
     * @returns 
     */
    public static getAllData<T extends BaseCsv>(name: string): Map<number, T> {
        if (BaseCsv.csvData.has(name)) {
            return BaseCsv.csvData.get(name)
        }
    }
    


}